package net.zjitc.domain;

import java.util.Objects;

/**
 * @Author: Administrator
 * @Date: 2020-04-26 11:17:49
 * 实体类/标准类/JavaBean
 * 与数据库表一一对应
 * 包含： 1）私有属性 （属性与表中字段对应）
 *       2）成员方法（setter/getter方法）
 *       3）构造方法（无参、有参）
 * 若需要还可以包含：
 *       4）重写toString方法
 *          直接输出student对象，实质会调用toString方法，若不重写，输出的是地址
 *       5）重写equals\hashCode方法
 *          比较俩对象是否相等，若不重写，比较的是地址，重写后比较的是内容
 */
public class Student {
    private int id;
    private String name;
    private String sex;
    private int age;
    /* Alt+Insert 键 选择相应方法，自动生成*/

    public Student() {
    }

    public Student(String name, String sex, int age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
    }

    public Student(int id, String name, String sex, int age) {
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return id == student.id &&
                age == student.age &&
                Objects.equals(name, student.name) &&
                Objects.equals(sex, student.sex);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, sex, age);
    }
}
